using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class BackpackItemUI : MonoBehaviour,IPointerClickHandler
{
    private Image itemIcon;
    private Text itemName;
    private Text itemNum;
    public GameObject selectBg;
    public ItemData itemData;
    private UIBase parent;
    public bool isSelected;

    private void Awake()
    {
        itemIcon = transform.Find("Icon").GetComponent<Image>();
        itemNum = transform.Find("Num").GetComponent<Text>();
        itemName = transform.Find("ItemName").GetComponent<Text>();
        selectBg = transform.Find("SelectImage").gameObject;
    }

    public void SetItemInfo(ItemData _itemData,int _count,UIBase _parent)
    {
        itemIcon.sprite = _itemData.icon;
        itemName.text = _itemData.itemName;
        itemNum.text = _count.ToString();
        itemData = _itemData;
        parent = _parent;
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        if ((isSelected)) return;
        parent.UpdateItemDetail(itemData);
        AudioManager.Instance.PlaySound((int)E_SoundType.Click);
    }

    public void IsSelected(bool select)
    {
        isSelected = select;
        selectBg.SetActive(select);
    }


}
